package project2;

import ExactMsa.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;

public class Main {


    /*********************************************************************
     * score_matrix[][] : matrix of 4x4
     * gap_cost : the cost for a gap in the alignment
     * k : the number of the sequences to align
     * n : the size of the longest sequence
     * seq[] : the input k sequences
    *********************************************************************/

    static int[][] score_matrix;
    static int gap_cost, n, k;
    static String[] seq;
    static precomputation p;


    /*********************************************************************
     * set the values for global varibales
    *********************************************************************/

    static void set() {
        score_matrix = new int[4][4];
        score_matrix[0][0] = 0;score_matrix[0][1] = 5;score_matrix[0][2] = 2;score_matrix[0][3] = 5;
        score_matrix[1][0] = 5;score_matrix[1][1] = 0;score_matrix[1][2] = 5;score_matrix[1][3] = 2;
        score_matrix[2][0] = 2;score_matrix[2][1] = 5;score_matrix[2][2] = 0;score_matrix[2][3] = 5;
        score_matrix[3][0] = 5;score_matrix[3][1] = 2;score_matrix[3][2] = 5;score_matrix[3][3] = 0;
        gap_cost = 5;
        k = 5;
        seq = new String[k];
        //seq[0] = "aacga";
        //seq[1] = "cgttc";
        //seq[2] = "tagcg";
        seq[0] = "tatggagagaataaaagaactgagagatctaatgtcgcagtcccgcactcgcgagatact"+
                    "cactaagaccactgtggaccatatggccataatcaaaaag";
        seq[1] = "atggatgtcaatccgactctacttttcctaaaaattccagcgcaaaatgccataagcacc"+
                    "acattcccttatactggagatcctccatacagccatggaa";
        seq[2] = "tccaaaatggaagactttgtgcgacaatgcttcaatccaatgatcgtcgagcttgcggaa"+
                    "aaggcaatgaaagaatatggggaagatccgaaaatcgaaa";
        seq[3] = "aaaagcaacaaaaatgaaggcaatactagtagttctgctatatacatttgcaaccgcaaa"+
                    "tgcagacacattatgtataggttatcatgcgaacaattca";
        seq[4] = "atgagtgacatcgaagccatggcgtctcaaggcaccaaacgatcatatgaacaaatggag"+
                    "actggtggggagcgccaggatgccacagaaatcagagcat";
        n = seq[0].length();
        p = new precomputation(score_matrix,gap_cost,seq,k,n);
    }

    
    public static void main(String[] args) {

        set();

        //exact MSA
        /*new ExactMsaThreeSequences(seq,IOHandler.readScoreMatrix(my_path+"matrix.txt"), gap_cost).printOutput();
        //new ExactMsaFourSequences(seq,IOHandler.readScoreMatrix(my_path+"matrix.txt"), gap_cost);
         * */
        
        String my_path = new String();
        my_path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        my_path = my_path.substring(0, my_path.lastIndexOf('/')+1);
        my_path = my_path.replaceAll("%20", " ");

        
        try{
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(my_path+"result.out")));

            //approximation
            //approximate a = new approximate(score_matrix,gap_cost,seq,k,n,p);
            //a.approximation(out);

            //forward dynammic programming
            FDP f = new FDP(score_matrix,gap_cost,seq,k,n,p);
            System.out.println();
            System.out.println("Result of fdp: ");
            double time = System.nanoTime();
            f.run_upper_bound(out,2700);
            double end_time = (System.nanoTime()-time)/1000000000;
            out.println("Running time: "+end_time+" s");

            //compute the optimal cost for 5 seq
            /*exact_5 e = new exact_5(score_matrix,gap_cost,seq,k,n);
            e.get_optimal_cost();*/

            out.close();

        }
        catch(Exception e){
            e.printStackTrace();
        }

    }

}
